﻿#region License
// /* **************************************************************
// * Copyright (C) intex Consulting GmbH - All Rights Reserved    *
// *--------------------------------------------------------------*
// * Unauthorized copying of this file, via any medium is         *
// * strictly prohibited                                          *
// *--------------------------------------------------------------*
// * Proprietary and confidential                                 *
// *--------------------------------------------------------------*
// * Dissasembling/modifications strictly prohibited!             *
// ***************************************************************/
#endregion

using System;
using System.Diagnostics.CodeAnalysis;
using ComHlp.enums;

namespace ComHlp.ContentClasses.Connections
{
    /// <summary> connections class </summary>
    [Serializable]
    [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
    [SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")]
    public class ClientConnection
    {
        /// <summary> Name of the connection </summary>
        public string Name { get; set; }

        /// <summary> Identifier which gets passed to client for startup </summary>
        public string Identifier { get; set; }

        /// <summary> Hostname of the intex server </summary>
        public string ServerHostname { get; set; }

        /// <summary> Service number on which the intex server is running </summary>
        public int ServerService { get; set; }

        /// <summary> codepage to use </summary>
        public ItxCompression Compression { get; set; }

        /// <summary> Defines if the server is an i5 </summary>
        public bool I5Host { get; set; }

        /// <summary> PGM to sent to the i5 server </summary>
        public string I5Pgm { get; set; }

        /// <summary> codepage to use </summary>
        public ItxCodepage Codepage { get; set; }
        
        /// <summary> protocoll start program </summary>
        public string StartProgram { get; set; }

        public EConnectionLocation ConnectionLocation { get; set; }


        /// <summary> Default constructor </summary>
        public ClientConnection()
        {
            Name = "";
            Identifier = "";
            ServerHostname = "";
            ServerService = 0;
            I5Host = false;
            I5Pgm = "";
            StartProgram = "";
            Codepage = ItxCodepage.Cp850;
            Compression = ItxCompression.None;
        }

        public bool Verify()
        {
            if (string.IsNullOrEmpty(Name))
                return false;
            if (string.IsNullOrEmpty(Identifier))
                return false;
            if (string.IsNullOrEmpty(ServerHostname))
                return false;
            if (ServerService < 1024 || ServerService > 65000)
                return false;
            if (I5Host && string.IsNullOrEmpty(I5Pgm))
                return false;

            return true;
        }
    }
}